#include "OurDetectorConstruction.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4Sphere.hh"
#include "OurSensitiveDetector.hh"
#include "globals.hh"
#include <math.h>
#include "G4Colour.hh"
#include "G4VisAttributes.hh"

OurDetectorConstruction::
	OurDetectorConstruction()
{
	G4cout << "Begin of OurDetectorConstruction constructor. \n";
	G4cout << "End of OurDetectorConstruction constructor. \n";
}

OurDetectorConstruction::
	~OurDetectorConstruction()
{
	G4cout << "Begin of OurDetectorConstruction destructor. \n";
	G4cout << "End of OurDetectorConstruction destructor. \n";
}

G4VPhysicalVolume* OurDetectorConstruction::
	Construct()
{ 
	G4cout << "Begin of OurDetectorConstruction::Construct() \n";	
   G4double x,y,z,leadInnerRadius,leadOuterRadius,PI,tissuex,tissuey,tissuez;
   x = 250*cm;
   y = 250*cm;
   z = 250*cm;
   leadInnerRadius=4*cm;
   leadOuterRadius=9*cm;
   PI=atan(1)*4;
   tissuex = 24.13*cm;
   tissuey = 45.72*cm;
   tissuez = 175.26*cm;
  G4Material* Air =
  G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");

  G4Element* NitrogenElement = 
	G4NistManager::Instance()->FindOrBuildElement(7);

	G4Material* NitrogenVacuum = new G4Material("NitrogenVacuum",1E-25*g/cm3,1);
	NitrogenVacuum->AddElement(NitrogenElement,1.0);
  
    G4Box*  
  solidWorld = new G4Box("World",//its name 
  x/2,y/2,z/2);//these are the dimensions of the box. Divide by two because it treats dimensions from center.

  G4LogicalVolume*                         
  logicWorld = new G4LogicalVolume(solidWorld,		//its solid
                                   NitrogenVacuum,			//its material
                                   "World");		//its name
  G4VPhysicalVolume*                                   
  physiWorld = new G4PVPlacement(0,			//no rotation
  				 G4ThreeVector(0,0,0),	//at (0,0,0)
                                 logicWorld,		//its logical volume
                                 "World",		//its name
                                 0,			//its mother  volume
                                 false,			//no boolean operation
                                 0);			//copy number	
								 
								 
	G4Element* LeadElement = 
	G4NistManager::Instance()->FindOrBuildElement(82);
	
	G4Material* Lead = new G4Material("LeadMaterial",11.34*g/cm3,1);
	Lead->AddElement(LeadElement,1.0);

	
	
	G4Sphere* solidLead = new     G4Sphere("LeadName",leadInnerRadius,leadOuterRadius,0,2*PI,
    0,2*PI);
    
	//solid voume
	G4LogicalVolume* logicLead = new G4LogicalVolume(solidLead,Lead,"LeadName");

	G4VisAttributes* LeadAttributes = new G4VisAttributes(G4Colour::Cyan());
	LeadAttributes->SetForceSolid(true);
	logicLead->SetVisAttributes(LeadAttributes);
    // solid,material,itsname
	G4VPhysicalVolume*
		physiLead = new G4PVPlacement(0,G4ThreeVector(0,0,0),logicLead,"LeadName",logicWorld,false,0);
 
 
 
//Make Tissue 
 G4Material* Tissue = 
	G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER");
	
     G4Box*  
  solidTissue = new G4Box("TissueName",tissuex/2,tissuey/2,tissuez/2);


  G4LogicalVolume*                         
  logicTissue = new G4LogicalVolume(solidTissue,		//its solid
                                   Tissue,			//its material
                                   "TissueName", //its name
								   0, // electro magnetic field manager (none)
								   new OurSensitiveDetector("sensitive_tissue")); //set a sensitive detector	
  G4VPhysicalVolume*                                   
  physiTissue = new G4PVPlacement(0,			//no rotation
  				 G4ThreeVector(47.545*cm,0,0),	//at (0,0,30)
                                 logicTissue,		//its logical volume
                                 "TissueName",		//its name
                                 logicWorld,			//its mother  volume
                                 false,			//no boolean operation
                                 0);			//copy number	

  G4VisAttributes* TissueAttributes = new G4VisAttributes(G4Colour::Magenta());
  TissueAttributes->SetForceSolid(true);
  logicTissue->SetVisAttributes(TissueAttributes);
 
G4cout << "End of OurDetectorConstruction::Construct() \n";	
return physiWorld;								 
}
